package com.git.hui.yinshua.biz.rest.app.wx;

import com.alibaba.fastjson.JSONObject;
import com.git.hui.yinshua.api.model.ResVo;
import com.git.hui.yinshua.api.model.permission.Permission;
import com.git.hui.yinshua.api.model.permission.UserAccessRole;
import com.git.hui.yinshua.biz.order.service.OrderService;
import com.git.hui.yinshua.biz.pay.service.PaymentService;
import com.git.hui.yinshua.biz.pay.service.RefundService;
import com.git.hui.yinshua.biz.pay.service.wx.IWxPayService;
import com.git.hui.yinshua.common.DateUtil;
import com.wechat.pay.java.service.payments.model.Transaction;
import com.wechat.pay.java.service.refund.model.RefundNotification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.UUID;

/**
 * 微信支付回调
 *
 * @author YiHui
 * @date 2024/7/4
 */
@Slf4j
@RestController
@RequestMapping(path = "app/wx")
public class WxCallbackController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private IWxPayService wxPayService;
    @Autowired
    private PaymentService paymentService;
    @Autowired
    private RefundService refundService;


    /**
     * 微信支付回调
     *
     * @param request
     * @return
     * @throws IOException
     */
    @PostMapping(path = "payNotify")
    public ResponseEntity<?> wxPayCallback(HttpServletRequest request) throws IOException {
        return wxPayService.callback(request, paymentService::wxPayCallback);
    }


    /**
     * 退款回调
     *
     * @return
     */
    @PostMapping(path = "refundNotify")
    public ResponseEntity<?> wxRefundCallback(HttpServletRequest request) throws IOException {
        return wxPayService.refundCallback(request, refundService::refundCallback);
    }

}
